home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / dev / mui / mui37_de.lha / Amiga-E / Examples / Slidorama.e < prev    next >
Text File  |  1996-08-25  |  15KB  |  410 lines

  1. /*
  2. ** Demosource on how to use customclasses in E.
  3. ** Based on the C example 'Slidorama.c' by Stafan Stuntz.
  4. ** Translated TO E by Sven Steiniger
  5. **
  6. ** Sorry FOR some uppercase words in the comments. This IS because OF
  7. ** my AutoCase-dictionary
  8. */
  9.  
  10. OPT PREPROCESS
  11.  
  12. MODULE 'muimaster','libraries/mui','libraries/muip',
  13.        'intuition/classes','intuition/classusr','intuition/screens','intuition/intuition',
  14.        'utility','utility/tagitem',
  15.        'amigalib/boopsi',
  16.        'mui/muicustomclass'
  17.  
  18. CONST MUIA_Mousepower_Direction=TAG_USER+$10001   -> was: ((TAG_USER | ( 1 << 16)) | 0x0001)
  19.  
  20. OBJECT mousepowerData
  21.   decrease:INT
  22.   mousex:INT
  23.   mousey:INT
  24.   direction:INT
  25. ENDOBJECT
  26.  
  27. OBJECT ratingData
  28.   buf:PTR TO CHAR
  29. ENDOBJECT
  30.  
  31. OBJECT timeData
  32.   buf:PTR TO CHAR
  33. ENDOBJECT
  34.  
  35. DEF mousepowerClass=NIL:PTR TO mui_customclass,
  36.     ratingClass=NIL:PTR TO mui_customclass,
  37.     timebuttonClass=NIL:PTR TO mui_customclass,
  38.     timesliderClass=NIL:PTR TO mui_customclass
  39.  
  40.  
  41. /*****************************************************************************
  42. ** This is the Mousepower custom class, a sub class of Levelmeter.mui.
  43. ** It is quite simple and does nothing but add some input capabilities
  44. ** to its super class by implementing MUIM_HandleInput.
  45. ** Don't be afraid of writing sub classes!
  46. ******************************************************************************/
  47.  
  48. PROC mousepowerDispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  49. DEF methodid,
  50.     data:PTR TO mousepowerData,
  51.     m:PTR TO muip_handleinput,
  52.     delta
  53.  
  54.    methodid:=msg.methodid
  55.    SELECT methodid
  56.      CASE OM_NEW
  57.        IF obj:=doSuperMethodA(cl,obj,msg)
  58.          data:=INST_DATA(cl,obj)
  59.          data.mousex    :=-1
  60.          data.direction := GetTagData(MUIA_Mousepower_Direction,0,msg::opset.attrlist)
  61.          set(obj,MUIA_Numeric_Max,1000)
  62.        ENDIF
  63.        RETURN obj
  64.  
  65.      CASE MUIM_Setup
  66.        data:=INST_DATA(cl,obj)
  67.        IF doSuperMethodA(cl,obj,msg)=FALSE THEN RETURN FALSE
  68.        data.mousex  :=-1;
  69.        set(obj,MUIA_Numeric_Max,1000)
  70.        Mui_RequestIDCMP(obj,IDCMP_MOUSEMOVE OR IDCMP_INTUITICKS OR IDCMP_INACTIVEWINDOW)
  71.        RETURN MUI_TRUE
  72.  
  73.      CASE MUIM_Cleanup
  74.        Mui_RejectIDCMP(obj,IDCMP_MOUSEMOVE OR IDCMP_INTUITICKS OR IDCMP_INACTIVEWINDOW)
  75.        RETURN doSuperMethodA(cl,obj,msg)
  76.  
  77.      CASE MUIM_HandleInput
  78.        m:=msg
  79.        data:=INST_DATA(cl,obj)
  80.        IF m.imsg
  81.          IF m.imsg.class=IDCMP_MOUSEMOVE
  82.            IF data.mousex<>-1
  83.              IF data.direction=1
  84.                delta := Abs(data.mousex - m.imsg.mousex)*2
  85.              ELSEIF data.direction=2
  86.                delta := Abs(data.mousey - m.imsg.mousey)*2
  87.              ELSE
  88.                delta := Abs(data.mousex - m.imsg.mousex)+
  89.                         Abs(data.mousey - m.imsg.mousey)
  90.              ENDIF
  91.              IF data.decrease>0 THEN data.decrease:=data.decrease-1
  92.              doMethodA(obj,[MUIM_Numeric_Increase,delta/10])
  93.            ENDIF
  94.            data.mousex:=m.imsg.mousex
  95.            data.mousey:=m.imsg.mousey
  96.          ELSEIF m.imsg.class=IDCMP_INTUITICKS
  97.            doMethodA(obj,[MUIM_Numeric_Decrease,data.decrease*data.decrease])
  98.            IF data.decrease<50 THEN data.decrease:=data.decrease+1
  99.          ELSEIF m.imsg.class=IDCMP_INACTIVEWINDOW
  100.            set(obj,MUIA_Numeric_Value,0)
  101.          ENDIF
  102.        ENDIF
  103.        RETURN 0
  104.   ENDSELECT
  105. ENDPROC doSuperMethodA(cl,obj,msg)
  106.  
  107.  
  108. /*****************************************************************************
  109. ** This is the Rating custom class, a sub class of Slider.mui.
  110. ** It shows how to override the MUIM_Numeric_Stringify method
  111. ** to implement custom displays in a slider gadget. Nothing
  112. ** easier than that... :-)
  113. ******************************************************************************/
  114.  
  115. PROC ratingDispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  116. DEF methodid,
  117.     data:PTR TO ratingData,
  118.     m:PTR TO muip_numeric_stringify,
  119.     r
  120.  
  121.   methodid:=msg.methodid
  122.   SELECT methodid
  123.  
  124.     CASE OM_NEW
  125.       /* E-Note: because you could not use STRING-type as member OF an object,
  126.       ** so we have TO allocate it. This IS done during OM_NEW
  127.       */
  128.       IF (obj:=doSuperMethodA(cl,obj,msg))=NIL THEN RETURN 0
  129.       data:=INST_DATA(cl,obj)
  130.       data.buf:=String(20)
  131.       IF data.buf THEN RETURN obj
  132.  
  133.       ->Allocating failed therefore invoke OM_DISPOSE on *our* class
  134.       coerceMethodA(cl,obj,[OM_DISPOSE])
  135.       RETURN 0
  136.  
  137.     CASE OM_DISPOSE
  138.       /* E-Note: Lets dispose our String
  139.       */
  140.       data:=INST_DATA(cl,obj)
  141.       IF data.buf THEN DisposeLink(data.buf)
  142.       data.buf:=NIL
  143.  
  144.     CASE MUIM_Numeric_Stringify
  145.       data:=INST_DATA(cl,obj)
  146.       m:=msg
  147.       IF m.value=0
  148.         StrCopy(data.buf,'You''re kidding!',STRLEN)
  149.       ELSEIF m.value=100
  150.         StrCopy(data.buf,'It''s magic!',STRLEN)
  151.       ELSE
  152.         r:=doMethodA(obj,[MUIM_Numeric_ValueToScale,0,4 /*5 States, 0..4*/])
  153.         StringF(data.buf,
  154.                 '\d[3] points. \s',
  155.                 m.value,ListItem([':-((',':-(',':-|',':-)',':-))'],r))
  156.       ENDIF
  157.       RETURN data.buf
  158.   ENDSELECT
  159. ENDPROC doSuperMethodA(cl,obj,msg)
  160.  
  161.  
  162. /*****************************************************************************
  163. ** A time slider custom class. Just like with the Rating class, we override
  164. ** the MUIM_Numeric_Stringify method. Wow... our classes get smaller and 
  165. ** smaller. This one only has about 10 lines of C code. :-)
  166. ** Note that we can use this TimeDispatcher as subclass of any of
  167. ** MUI's numeric classes. In Slidorama, we create a Timebutton class
  168. ** from MUIC_Numericbutton and Timeslider class for MUIC_Slider with
  169. ** the same dispatcher function.
  170. ******************************************************************************/
  171.  
  172. PROC timeDispatcher(cl:PTR TO iclass,obj:PTR TO object,msg:PTR TO msg)
  173. DEF methodid,
  174.     data:PTR TO timeData,
  175.     m:PTR TO muip_numeric_stringify
  176.  
  177.   methodid:=msg.methodid
  178.   SELECT methodid
  179.     CASE OM_NEW
  180.       /* E-Note: because you could not use STRING-type as member OF an object,
  181.       ** so we have TO allocate it. This IS done during OM_NEW
  182.       */
  183.       IF (obj:=doSuperMethodA(cl,obj,msg))=NIL THEN RETURN 0
  184.       data:=INST_DATA(cl,obj)
  185.       data.buf:=String(16)
  186.       IF data.buf THEN RETURN obj
  187.  
  188.       ->Allocating failed therefore invoke OM_DISPOSE on *our* class
  189.       coerceMethodA(cl,obj,[OM_DISPOSE])
  190.       RETURN 0
  191.  
  192.     CASE OM_DISPOSE
  193.       /* E-Note: Lets dispose our String
  194.       */
  195.       data:=INST_DATA(cl,obj)
  196.       IF data.buf THEN DisposeLink(data.buf)
  197.       data.buf:=NIL
  198.  
  199.     CASE MUIM_Numeric_Stringify
  200.       data:=INST_DATA(cl,obj)
  201.       m:=msg
  202.       StringF(data.buf,'\z\d[2]:\z\d[2]',m.value/60,Mod(m.value,60))
  203.       RETURN data.buf
  204.   ENDSELECT
  205. ENDPROC doSuperMethodA(cl,obj,msg)
  206.  
  207.  
  208. /*****************************************************************************
  209. ** Main Program
  210. ******************************************************************************/
  211.  
  212. PROC cleanupClasses()
  213.   IF mousepowerClass THEN Mui_DeleteCustomClass(mousepowerClass)
  214.   IF ratingClass     THEN Mui_DeleteCustomClass(ratingClass)
  215.   IF timebuttonClass THEN Mui_DeleteCustomClass(timebuttonClass)
  216.   IF timesliderClass THEN Mui_DeleteCustomClass(timesliderClass)
  217. ENDPROC
  218.  
  219. PROC createCustomClass(father,datasize,dispatcher)
  220. DEF mcc
  221.   mcc:=eMui_CreateCustomClass(NIL,father,NIL,datasize,dispatcher)
  222.   IF mcc=NIL THEN Raise('Could not create custom class.')
  223. ENDPROC mcc
  224.  
  225. PROC setupClasses()
  226.   mousepowerClass := createCustomClass(MUIC_Levelmeter,SIZEOF mousepowerData,{mousepowerDispatcher})
  227.   ratingClass     := createCustomClass(MUIC_Slider,SIZEOF ratingData,{ratingDispatcher})
  228.   timesliderClass := createCustomClass(MUIC_Slider,SIZEOF timeData,{timeDispatcher})
  229.   timebuttonClass := createCustomClass(MUIC_Numericbutton,SIZEOF timeData,{timeDispatcher})
  230. ENDPROC
  231.  
  232. PROC main() HANDLE
  233. DEF app=NIL,window,
  234.     sigs=0
  235.  
  236.   IF (muimasterbase:=OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN))=NIL THEN
  237.      Raise('Failed TO open muimaster.library')
  238.  
  239.   IF (utilitybase:=OpenLibrary('utility.library',0))=NIL THEN
  240.      Raise('Failed TO open utility.library')
  241.  
  242.   setupClasses()
  243.  
  244.   app := ApplicationObject,
  245.       MUIA_Application_Title      , 'Slidorama',
  246.       MUIA_Application_Version    , '$VER: Slidorama 12.10 (21.11.95)',
  247.       MUIA_Application_Copyright  , '©1992-95, Stefan Stuntz',
  248.       MUIA_Application_Author     , 'Stefan Stuntz',
  249.       MUIA_Application_Description, 'Show different kinds OF sliders',
  250.       MUIA_Application_Base       , 'SLIDORAMA',
  251.  
  252.       SubWindow, window := WindowObject,
  253.           MUIA_Window_Title, 'Slidorama',
  254.           MUIA_Window_ID   , "SLID",
  255.  
  256.           WindowContents, VGroup,
  257.  
  258.               Child, HGroup,
  259.  
  260.                   Child, VGroup, GroupSpacing(0), GroupFrameT('Knobs'),
  261.                       Child, VSpace(0),
  262.                       Child, ColGroup(6),
  263.                           GroupSpacing(0),
  264.                           Child, VSpace(0),
  265.                           Child, HSpace(4),
  266.                           Child, CLabel('1'),
  267.                           Child, CLabel('2'),
  268.                           Child, CLabel('3'),
  269.                           Child, CLabel('4'),
  270.                           Child, VSpace(2),
  271.                           Child, VSpace(2),
  272.                           Child, VSpace(2),
  273.                           Child, VSpace(2),
  274.                           Child, VSpace(2),
  275.                           Child, VSpace(2),
  276.                           Child, Label('Volume:'),
  277.                           Child, HSpace(4),
  278.                           Child, newKnobObject1(64,64),
  279.                           Child, newKnobObject1(64,64),
  280.                           Child, newKnobObject1(64,64),
  281.                           Child, newKnobObject1(64,64),
  282.                           Child, Label('Bass:'),
  283.                           Child, HSpace(4),
  284.                           Child, newKnobObject2(-100,100),
  285.                           Child, newKnobObject2(-100,100),
  286.                           Child, newKnobObject2(-100,100),
  287.                           Child, newKnobObject2(-100,100),
  288.                           Child, Label('Treble:'),
  289.                           Child, HSpace(4),
  290.                           Child, newKnobObject2(-100,100),
  291.                           Child, newKnobObject2(-100,100),
  292.                           Child, newKnobObject2(-100,100),
  293.                           Child, newKnobObject2(-100,100),
  294.                       End,
  295.                       Child, VSpace(0),
  296.                   End,
  297.  
  298.                   Child, VGroup,
  299.                       Child, VGroup, GroupFrameT('Levelmeter Displays'),
  300.                           Child, VSpace(0),
  301.                           Child, HGroup,
  302.                               Child, HSpace(0),
  303.                               Child, NewObjectA(mousepowerClass.mcc_class,0,
  304.                                                 [MUIA_Mousepower_Direction,1,
  305.                                                  MUIA_Levelmeter_Label,'Horizontal',
  306.                                                  TAG_DONE]),
  307.                               Child, HSpace(0),
  308.                               Child, NewObjectA(mousepowerClass.mcc_class,0,
  309.                                                 [MUIA_Mousepower_Direction,2,
  310.                                                  MUIA_Levelmeter_Label,'Vertical',
  311.                                                  TAG_DONE]),
  312.                               Child, HSpace(0),
  313.                               Child, NewObjectA(mousepowerClass.mcc_class,0,
  314.                                                 [MUIA_Mousepower_Direction,0,
  315.                                                  MUIA_Levelmeter_Label,'Total',
  316.                                                  TAG_DONE]),
  317.                               Child, HSpace(0),
  318.                           End,
  319.                           Child, VSpace(0),
  320.                       End,
  321.                       Child, VGroup, GroupFrameT('Numeric Buttons'),
  322.                           Child, VSpace(0),
  323.                           Child, HGroup, GroupSpacing(0),
  324.                               Child, HSpace(0),
  325.                               Child, ColGroup(4), MUIA_Group_VertSpacing, 1,
  326.                                   Child, VSpace(0),
  327.                                   Child, CLabel('Left'),
  328.                                   Child, CLabel('Right'),
  329.                                   Child, CLabel('SPL'),
  330.                                   Child, Label1('Low:'),
  331.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  332.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  333.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,30,99,'%2ld dB']),
  334.                                   Child, Label1('Mid:'),
  335.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  336.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  337.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,30,99,'%2ld dB']),
  338.                                   Child, Label1('High:'),
  339.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  340.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,0,100,'%3ld %%']),
  341.                                   Child, Mui_MakeObjectA(MUIO_NumericButton,[NIL,30,99,'%2ld dB']),
  342.                               End,
  343.                               Child, HSpace(0),
  344.                           End,
  345.                           Child, VSpace(0),
  346.                       End,
  347.                   End,
  348.               End,
  349.  
  350.               Child, VSpace(4),
  351.  
  352.               Child, ColGroup(2),
  353.                   Child, Label('Slidorama Rating:'),
  354.                   Child, NewObjectA(ratingClass.mcc_class,0,
  355.                                     [MUIA_Numeric_Value,50,
  356.                                      TAG_DONE]),
  357.               End,
  358.           End,
  359.       End,
  360.   End
  361.  
  362.   IF app=NIL THEN Raise('Failed TO create Application')
  363.  
  364.   doMethodA(window,[MUIM_Notify,MUIA_Window_CloseRequest,MUI_TRUE,
  365.                     app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit])
  366.  
  367.  
  368. /*
  369. ** This is the ideal input loop for an object oriented MUI application.
  370. ** Everything is encapsulated in classes, no return ids need to be used,
  371. ** we just check if the program shall terminate.
  372. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  373. ** from Wait() (or 0). This makes the input loop significantly faster.
  374. */
  375.  
  376.   set(window,MUIA_Window_Open,MUI_TRUE)
  377.  
  378.   WHILE Not(doMethodA(app,[MUIM_Application_NewInput,{sigs}]) = MUIV_Application_ReturnID_Quit)
  379.     IF sigs THEN sigs := Wait(sigs)
  380.   ENDWHILE
  381.  
  382.   set(window,MUIA_Window_Open,FALSE)
  383.  
  384. /*
  385. ** Shut down...
  386. */
  387.  
  388. EXCEPT DO
  389.   IF app THEN Mui_DisposeObject(app)                /* dispose ALL objects. */
  390.   cleanupClasses()
  391.   IF utilitybase THEN CloseLibrary(utilitybase)     /* close library */
  392.   IF muimasterbase THEN CloseLibrary(muimasterbase) /* close library */
  393.   IF exception THEN WriteF('\s\n',exception)
  394. ENDPROC
  395.  
  396. PROC newKnobObject1(max,defi) IS
  397.   KnobObject,
  398.       MUIA_Numeric_Max, max,
  399.       MUIA_Numeric_Default, defi,
  400.       MUIA_CycleChain,1,
  401.   End
  402.  
  403. PROC newKnobObject2(min,max) IS
  404.   KnobObject,
  405.       MUIA_Numeric_Max, max,
  406.       MUIA_Numeric_Min, min,
  407.       MUIA_CycleChain,1,
  408.   End
  409.  
  410.